package jztm;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.jsoup.nodes.Element;
/**
 *
 * @author mhl
 */
public class Parser {
    
    Document html_doc;
    
    public Parser(String address)
    {
        try {
		System.out.println("Parsuję: "+ address);	
            	this.html_doc= Jsoup.connect(address).get();
        }
        catch(IOException e) {
            System.out.println("Błąd wejścia/wyjścia: "+ e.toString());
            System.exit(-1);
        }
    }
    
    public Elements getAllLinks() { 
        Elements links = this.html_doc.select("a[href]");
        return links;     
    }
    public final Elements getMainLinks(Elements lista)
    {
         Elements ret_elem= new Elements();
         for(Element link : lista)
         {
             if(link.text().contains("szukaj") && !link.toString().contains("exe")) {
                 System.out.println("DEBUG: "+ link.text() + " - "+ link.attr("abs:href"));
                 ret_elem.add(link);
             }
         }
         return ret_elem;
    }
}

